home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / comm / tcp / rxsocket.lha / rxsocket / examples / authfun.rexx < prev    next >
OS/2 REXX Batch file  |  2000-11-28  |  1KB  |  48 lines

  1. /*
  2.     This is an auth function.
  3.     It wants 3 arguments:
  4.     - ha the remote host
  5.     - lp the localport number
  6.     - sp the remoteport number
  7.     Auth is a tcp service which gives informations about a
  8.     connection.
  9.     Let's suppose someone connected you on tcp port 4000, like in
  10.     revserv.rexx. If you want to know who it is you can try auth
  11.     service.
  12.     The function returns a string beginning with:
  13.     +OK     it was able to connect the auth service
  14.     -ERR    an error occurred (e.g. connection refused)
  15. */
  16.  
  17. parse arg ha, lp, sp
  18.  
  19. say ha lp sp
  20.  
  21. sin.addrFamily = "INET"
  22. sin.addrAddr = ha
  23. if GetServByName("SE","auth","tcp")<0 then sin.addrPort = se.servPort
  24. else sin.addrPort = 113
  25.  
  26. say sin.addrFamily sin.addrAddr sin.addrPort
  27.  
  28. sock = socket("INET","STREAM",0)
  29. if sock<0 then exit "-ERR 1"
  30.  
  31. if connect(sock,"SIN")<0 then exit "-ERR 2"
  32.  
  33. request = lp "," sp || d2c(13) || d2c(10)
  34. res = send(sock,request)
  35. if res ~= length(request) then "-ERR 3"
  36.  
  37. ans=""
  38. len = recv(sock,"BUF",1)
  39. do while len>0
  40.     ans = ans || buf
  41.     len = recv(sock,"BUF",256)
  42. end
  43. if len<0 then exit "-ERR 4" errno()
  44.  
  45. call CloseSocket(sock)
  46.  
  47. return "+OK " || left(ans,length(ans)-1)
  48.